package com.lmf.annotation;


import com.lmf.annotation.bean.MyApplicationEvent;
import com.lmf.annotation.config.MyConfigOfApplicationListener;
import org.junit.Test;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 测试监听器
 */
public class IOCTest_BeanApplicationListener {
    // 测试自定义监听器  以及  测试事件监听注解：@EventListener
    @Test
    public void test01() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyConfigOfApplicationListener.class);
//        发布一个事件
        applicationContext.publishEvent(new ApplicationEvent(new String("lmf发布的事件")) {
        });
        //发布第二个事件
        applicationContext.publishEvent(new MyApplicationEvent("xc发布事件"));
        // 关闭容器
        applicationContext.close();
    }
}
